using Avalonia.Controls;
using Avalonia.Interactivity;
using System.Threading.Tasks;

namespace DesktopApp.Views
{
    public partial class InputDialog : Window
    {
        public InputDialog()
        {
            InitializeComponent();
            // Find controls by name after initialization
            this.FindControl<Button>("OkButton")!.Click += OkButton_Click;
            this.FindControl<Button>("CancelButton")!.Click += CancelButton_Click;
        }

        // Static method to show the dialog and get input
        public static async Task<string?> ShowAsync(Window owner, string title, string message, string defaultInput = "")
        {
            var dialog = new InputDialog
            {
                Title = title,
            };
            dialog.FindControl<TextBlock>("MessageTextBlock")!.Text = message;
            dialog.FindControl<TextBox>("InputTextBox")!.Text = defaultInput;

            var result = await dialog.ShowDialog<string?>(owner);
            return result;
        }

        private void OkButton_Click(object? sender, RoutedEventArgs e)
        {
            Close(this.FindControl<TextBox>("InputTextBox")!.Text);
        }

        private void CancelButton_Click(object? sender, RoutedEventArgs e)
        {
            Close(null);
        }
    }
} 